package com.wxiao.exam.controller.manager;


import com.wxiao.exam.MajorService;
import com.wxiao.exam.PageBean;
import com.wxiao.exam.Result;
import com.wxiao.exam.pojo.MajorDO;
import com.wxiao.exam.pojo.vo.MajorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/admin/major")
public class ManageMajorController {

    @Autowired
    MajorService majorService;

    @Value("#{properties['major.pageSize']}")
    int pageSize;//列表大小

    @Value("#{properties['major.navigatePages']}")
    int size;//页码大小


    @RequestMapping("/list")
    public String list(@Validated MajorVO query, Model model) throws Exception {
        query.setPageSize(pageSize);
        query.setSize(size);
        PageBean<MajorDO> pageBean = majorService.listMajor(query);
        model.addAttribute("pageBean", pageBean);
        model.addAttribute("query", query);
        return "admin/major_list";
    }


    /**
     * 添加专业
     */
    @RequestMapping("/add")
    @ResponseBody
    public Result add(MajorVO major) throws Exception {
        return majorService.addMajor(major);
    }


}
